package com.icss.train_sys_back.mapper.system_manage;

import com.icss.train_sys_back.entity.system_manage.MenuEntity;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author 小泽
 * @createTime 2025/9/29 14:23
 */
@Mapper
public interface MenuManageMapper {
    //获取所有菜单列表
    @Select("select * from t_menu")
    List<MenuEntity> getAllMenus();


    //分页+条件查询菜单列表
    List<MenuEntity> getListConditions(String menuName, String menuUrl, Integer parentId, Integer isShow);

    //菜单添加
    @Insert("insert into t_menu values (null,#{menuName},#{menuUrl},#{parentId},#{menuIcon},#{menuOrder},#{isShow},now(),now())")
    void add(MenuEntity menu);

    //菜单更新
    @Update("update t_menu set menu_name = #{menuName},menu_url = #{menuUrl},parent_id = #{parentId},menu_icon = #{menuIcon}," +
            "menu_order = #{menuOrder},is_show = #{isShow},create_time = #{createTime},update_time = now() where menu_id = #{menuId}")
    void update(MenuEntity menu);

    //菜单启用停用状态管理
    @Update("update t_menu set is_show = #{isShow} where menu_id = #{menuId}")
    void changeStatus(Integer menuId, Integer isShow);

    //根据menuId 删除菜单
    @Delete("delete from t_menu where menu_id = #{menuId}")
    void delete(Integer menuId);

    //根据RoleId 获取菜单列表进行菜单加载
    //先查所有MenuId
    @Select("select menu_id from t_menu_role  where role_id = #{roleId}")
    List<Integer> getAllMenuIdsByRoleId(Integer roleId);

    //根据RoleId 获取菜单列表进行菜单加载
    //再根据MenuId 查所有的Menu实体类
    List<MenuEntity> getMenusByMenuIds(@Param("menuIds") List<Integer> menuIds);
}
